#include "Sparks.h"

Sparks::Sparks(PlayerPosition pos, VisualObject* vObj, GameObject *iBall):
	playerposition(pos),
	visualobject(vObj),
	ball(iBall)
{
	representation = visualobject;
	if(pos == PP_RIGHT)
		representation->loadImage("images/sparksright.png");
	if(pos == PP_LEFT)
		representation->loadImage("images/sparksleft.png");
	
	timeAlive = 0;
	totalLifeTime = 0.05; // live for 0.1 sec
	canDie = false;

	y = ball->y;

	// x will indicate the point of contact. If we're hitting the left paddle, that point is
	// left of the ball. If we're hitting the right paddle, that point is to the right of our ball.
	if(playerposition == PP_RIGHT)
		x = ball->x + ball->getWidth()/2;

	if(playerposition == PP_LEFT)
		x = ball->x - ball->getWidth()/2;
}

Sparks::~Sparks(void)
{
}

void Sparks::update(const double timePassed)
{
	timeAlive += timePassed;
	if(timeAlive > totalLifeTime)
		canDie = true;
}
void Sparks::getReadyForDraw()
{

	
	// our (x,y) values indicate the point of contact
	if(playerposition == PP_RIGHT)
		representation->setOffsetX(x-getWidth());

	if(playerposition == PP_LEFT)
		representation->setOffsetX(x+getWidth());

	representation->setOffsetY(y-getHeight()/2);
}

bool Sparks::canBeDeleted()
{
	return canDie;

}

